<template>
  <view class="profile">
    <view class="top">
      <view class="logo">
        <view class="image">LOGO</view>
      </view>
    </view>
    <view class="card">
      <view class="topBar">
        <text>角色切换</text>
        <u-icon
          name="userswitch"
          size="60"
          custom-prefix="custom-icon"
          @click="switchRolesTo"
        ></u-icon>
      </view>
      <view class="userInfo">
        <view class="avatar">
          <view class="circle"></view>
        </view>
        <view class="user-name">张三</view>
        <view class="change-info" @click="toChangeInfo">
          <text>修改基本信息</text>
          <u-icon
            name="edit"
            size="28"
            custom-prefix="custom-icon"
            @click="switchRolesTo"
          ></u-icon>
        </view>
      </view>
      <view class="complete">
        <view class="list">
          <text>词组完成</text>
          <view class="number">80</view>
        </view>
        <view class="list"
          ><text>句子完成</text>
          <view class="number">80</view>
        </view>
      </view>
      <button class="button_exit" @click="logoutModal">退出登录</button>
    </view>
    <!-- <view class="bottombar">
      <view class="bottom">
        <view class="expires">
          <view>有效工时</view>
          <view>120min</view>
        </view>
        <view class="money" @click="withdraw">
          <view>可提现</view>
          <view>¥10</view>
        </view>
        <view class="message" @click="prompt('uni-prompt')">
          <view>提现信息<br />查询</view>
        </view>
      </view>
      <button class="button_exit" @click="logoutModal">退出登录</button>
    </view> -->
    <view>
      <u-modal
        v-model="switchRole"
        @cancel="roleCancel"
        @confirm="roleConfirm"
        :async-close="true"
        :show-cancel-button="true"
        :content="`是否切换为${this.roleID}？`"
        confirm-color="#88031E"
        :show-title="false"
      ></u-modal>
      <u-modal
        v-model="warning"
        @cancel="warningCancel"
        @confirm="warningConfirm"
        :async-close="true"
        :show-cancel-button="true"
        confirm-color="#88031E"
        :show-title="false"
      >
        <view class="slot-content">
          <rich-text :nodes="content"></rich-text>
        </view>
      </u-modal>
      <u-modal
        v-model="logout"
        @cancel="logoutCancel"
        @confirm="logoutConfirm"
        :async-close="true"
        :show-cancel-button="true"
        content="确定退出登录？"
        confirm-color="#88031E"
        :show-title="false"
      >
      </u-modal>
      <u-top-tips ref="uSwitch"></u-top-tips>
    </view>
    <u-no-network></u-no-network>
    <!-- <prompt
      :show="promptType === 'uni-prompt'"
      @onConfirm="onConfirm"
      @onCancel="prompt('')"
      title="提现金额确认"
      text="请输入本次提现金额：（元）"
    ></prompt> -->
    <!-- <u-modal
      v-model="show"
      :title-style="{ color: 'red' }"
      @confirm="modalConfirm"
      :async-close="true"
      :show-title="false"
    >
      <view class="slot-content">
        <rich-text :nodes="content"></rich-text>
      </view>
    </u-modal> -->
  </view>
</template>

<script>
// UI有变动，故暂时不引入原来设置的可输入弹窗。
// import prompt from "../../components/uni-prompt/uni-prompt.vue";
export default {
  data() {
    return {
      switchRole: false,
      logout: false,
      warning: false,
      src: "https://cdn.uviewui.com/uview/example/fade.jpg",
      promptType: "",
      show: false,
      // fee: undefined,
      // content: `
      // 		<strong>您的本次提现申请已提交。</strong><br>
      //     请随后留意银行到账通知。<br>
      // 	`,
      content: `
					不能切换采集者<br>
					请完善基本信息
				`,
      roleID: "",
      roleKey: -1,
    };
  },
  components: {
    // prompt,
  },
  onLoad() {
    // 0-学习者， 1-采集者
    let roleKey = uni.getStorageSync("role_key");
    this.roleKey = roleKey;
    console.log("onLoad this.switchRole", this.switchRole);
    if (roleKey === 0) this.roleID = "采集者";
    else this.roleID = "学习者";
  },
  methods: {
    toChangeInfo() {
      this.switchRole = false;
      uni.navigateTo({
        url: "../myRecordChangeInfo/myRecordChangeInfo",
      });
    },
    // UI取消了查看提现账单的功能
    // withdraw() {
    //   uni.navigateTo({
    //     url: "../withdrawRecord/withdrawRecord",
    //   });
    // },
    switchRolesTo() {
      this.switchRole = true;
      if (this.roleKey === 0) {
        this.roleID = "采集者";
      } else {
        this.roleID = "学习者";
      }
    },
    logoutModal() {
      this.logout = true;
    },
    roleConfirm() {
      // 如果是学习者切换成采集者
      if (this.roleKey === 0) {
        this.switchRole = false;
        this.warning = true;
      } else {
        setTimeout(() => {
          this.switchRole = false;
          this.$refs.uSwitch.show({
            title: "已成功切换角色",
          });
          uni.removeStorageSync("role_key");
          if (this.roleKey === 0) {
            this.roleKey = 1;
          } else {
            this.roleKey = 0;
          }
          uni.setStorageSync("role_key", this.roleKey);
        }, 500);
      }
    },
    roleCancel() {
      this.switchRole = false;
    },
    logoutConfirm() {
      setTimeout(() => {
        this.logout = false;
        uni.clearStorageSync();
        uni.reLaunch({
          url: "../login/login",
        });
      }, 1000);
    },
    logoutCancel() {
      this.logout = false;
    },
    warningConfirm() {
      uni.removeStorageSync("role_key");
      this.roleKey = 1;
      uni.setStorageSync("role_key", this.roleKey);
      uni.reLaunch({
        url: "../myRecordChangeInfo/myRecordChangeInfo",
      });
    },
    warningCancel() {
      this.warning = false;
    },
    // prompt(type) {
    //   console.log(type);
    //   this.promptType = type;
    // },
    // onConfirm(e) {
    //   console.log(e);
    //   let _cost = e;
    //   if (_cost == "") {
    //     uni.showToast({
    //       title: "请输入提现金额哦",
    //       icon: "none",
    //     });
    //     return;
    //   } else {
    //     // 加载loading、发送请求
    //     this.fee = _cost;
    //     console.log(this.fee);
    //     this.promptType = "";
    //     this.show = true;
    // uni.request({
    //   url: `${this.$serverUrl}/mysetting/addMySetting`,
    //   method: "POST",
    //   header: {
    //     "Content-Type": "application/x-www-form-urlencoded",
    //     token: this.$store.state.userInfo.token,
    //   },
    //   data: {
    //     userId: this.$store.state.userInfo.userId,
    //     title: _cost,
    //     startArea: this.startArea,
    //     endArea: this.endArea,
    //     invoiceType: this.invoiceType,
    //     invoiceTypeFlg: this.invoiceTypeFlg,
    //   },
    //   success: (e) => {
    //     console.log(e);
    //     uni.hideLoading();
    //     this.showMsg({
    //       title: e.data.msg,
    //       position: "bottom",
    //     });
    //   },
    //   fail: (e) => {
    //     uni.hideLoading();
    //     this.showMsg({
    //       title: "请求失败，请重试！",
    //       position: "bottom",
    //     });
    //   },
    // });
    //   }
    // },
    modalConfirm() {
      setTimeout(() => {
        this.show = false;
      }, 1000);
    },
  },
};
</script>

<style lang="less" scoped>
.profile {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: rgba(189, 195, 199, 0.4);
  .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 40vh;
    background-color: #fff;
    .logo {
      will-change: transform;
      width: 100vw;
      height: 30vh;
      background-color: #fff;
      display: flex;
      justify-content: center;
      align-items: center;
      .image {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 280rpx;
        height: 280rpx;
        background-color: rgba(136, 3, 30, 1);
        color: #fff;
        font-weight: bold;
        font-size: 60rpx;
        letter-spacing: 2rpx;
      }
    }
  }
  .card {
    width: 90vw;
    height: 60vh;
    box-shadow: 4rpx 4rpx 4rpx 2rpx rgba(0, 0, 0, 0.2);
    background-color: rgb(255, 255, 255);
    border: solid 1px rgba(189, 195, 199, 0.4);
    border-radius: 20rpx;
    margin-top: -80rpx;
    display: flex;
    flex-direction: column;
    padding: 3%;
    z-index: 999;
    .topBar {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      font-size: 30rpx;
      > text {
        margin-right: 10rpx;
      }
    }
    .userInfo {
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-bottom: 60rpx;
      .avatar {
        width: 140rpx;
        height: 140rpx;
        border-radius: 50%;
        background-color: rgb(255, 255, 255);
        border: solid 1px rgba(136, 3, 30, 0.8);
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 10rpx;
        .circle {
          width: 120rpx;
          height: 120rpx;
          border-radius: 50%;
          background-color: rgba(233, 183, 182, 1);
        }
      }
      .user-name {
        font-weight: bold;
        font-size: 30rpx;
        margin-bottom: 6rpx;
      }
      .change-info {
        color: rgba(189, 195, 199, 1);
        > text {
          margin-right: 10rpx;
        }
      }
    }
    .complete {
      padding: 2%;
      .list {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: solid 1px rgba(189, 195, 199, 0.4);
        height: 100rpx;
        font-size: 30rpx;
        font-weight: 700;
      }
    }
    .button_exit {
      width: 90%;
      margin-top: 10vh;
      border: solid 1px rgba(136, 3, 30, 0.8);
      color: rgba(136, 3, 30, 0.8);
      background-color: rgb(255, 255, 255);
      font-weight: bold;
      font-size: 36rpx;
    }
  }
  .slot-content {
    padding: 2%;
    text-align: center;
    font-size: 30rpx;
    color: #333;
    padding-left: 30rpx;
  }
}
</style>
